package com.alstudio.view;

import java.util.ArrayList;

import com.alstudio.utils.Mylog;
import com.alstudio.view.NoticeItem;
import com.alstudio.view.listener.NoticeItemManagerListener;

public class NoticeItemManager{
	
	
	private final String TAG = "NoticeItemManager";
	
	private ArrayList<NoticeItem> itemList = new ArrayList<NoticeItem>();
	
	private NoticeItemManagerListener mListener;
	
	public void setNoticeItemManager(NoticeItemManagerListener listener)
	{
		mListener = listener;
	}
	
	
	public synchronized void removeNoticeItem()
	{
		if(itemList.size() > 0)
		{
			NoticeItem item = itemList.get(0);
			itemList.remove(0);
			
			if(mListener != null)
			{
				mListener.onNoticeItemRemoved(item);
			}
		}
		
		if(itemList.size() == 0)
		{
			if(mListener != null)
			{
				mListener.onNoticeItemListEmpty();
			}
			Mylog.d(TAG,"notice list empty!");
		}
	}
	
	public synchronized void addNoticeItem(NoticeItem item)
	{
		Mylog.d(TAG,"new notice item added!type:"+item.getType());
		itemList.add(item);
		if(mListener != null)
		{
			mListener.onNewNoticeItemAdded(item);
		}
	}
	
	public synchronized NoticeItem getCurrentNoticeItem()
	{
		NoticeItem item = null;
		if(itemList.size() > 0)
		{
			item = itemList.get(0);
		}
		else
		{
			Mylog.d(TAG,"no next notice item!");
		}
		return item;
	}
	
	public synchronized NoticeItem getNextNoticeItem()
	{
		NoticeItem item = null;
		if(itemList.size() > 0)
		{
			item = itemList.get(0);
		}
		else
		{
			Mylog.d(TAG,"no next notice item!");
		}
		return item;
	}

}
